package com.bzm.config;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.annotation.Configuration;
import org.springframework.util.ResourceUtils;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyWebMvcConfig implements WebMvcConfigurer {

//	@Override
//	public void addViewControllers(ViewControllerRegistry registry) {
//		// 以前要访问一个页面需要先创建个Controller控制类，再写方法跳转到页面
//		registry.addViewController("/toLogin").setViewName("login");
//
//	}

	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		// 这个方法是用来配置静态资源的，比如html，js，css，等等	
		registry.addResourceHandler("/static/**").addResourceLocations(ResourceUtils.CLASSPATH_URL_PREFIX + "/static/");
		WebMvcConfigurer.super.addResourceHandlers(registry);
	}

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		// 这个方法用来注册拦截器，我们自己写好的拦截器需要通过这里添加注册才能生效
		// 排除拦截
		List<String> ePPUrl = new ArrayList<String>();
		ePPUrl.add("/static/**");
		ePPUrl.add("/login/**");
		ePPUrl.add("/register/**");	
		registry.addInterceptor(new LoginIntercept()).addPathPatterns("/**").excludePathPatterns(ePPUrl);
	}
}
